﻿@model IEnumerable<FCNS.ERP.Models.ErpCategoryCorS>

@{
    ViewBag.Title = (int)ViewData["IsP"]==1?"客户资料":"供应商资料";
    Layout = "~/Views/Shared/_Layout.cshtml";;
}

<h2>@ViewBag.Title</h2> 
<script type="text/javascript">
    $(document).ready(function () {
        function GetData(id,searchText) {
            var text = "";
            $.get("/Basic/CorSGet", {
                categoryId: id,
                isP:@ViewData["IsP"],
                searchText: searchText
            }, function (data) {
                text += data;
            });
            return text;
        }

        var table = $('.dataTable').DataTable();
        $('.dataTable tbody').on('click', 'td.details-control', function () {
            var tr = $(this).closest('tr');
            var row = table.row(tr);
            if (row.child.isShown()) {
                row.child.hide();
                tr.removeClass('shown');
            }
            else {
                row.child(GetData($(this).attr("data-Id"),"")).show();
                tr.addClass('shown');
                //调整列宽 
                for (j = 0; j < tr.children().length; j++) {
                    var w = $(".dataTable tr:eq(1) td:eq(" + j + ")").width();
                    $(".dataTableD tr:first td:eq(" + j + ")").width(w);
                }
            }
        });

        //取消默认事件，重新设置
        $('.dataTables_filter [type=search]').unbind();
        $('.dataTables_filter [type=search]').keypress(function (e) {
            if (e.keyCode == 13) {
                var result = GetData(-1, $('.dataTables_filter [type=search]').val());
                $(".dataTable tbody").html(result);
                $(".dataTable").DataTable();
                $('.dataTables_filter [type=search]').val("");
            }
        });
    });
</script>
<p>
    <a class="newObjA" href="/Basic/CorSNew?isP=@ViewData["IsP"]">新增</a> 
</p>
<table class="dataTable">
    <thead>
        <tr>
            <th></th>

            <th>
                类型
            </th>
            <th>
                名称
            </th>
            <th>
                电话
            </th>
            <th>
                Email
            </th>

            <th>
                地址
            </th>
            <th></th>
        </tr>
    </thead>
    <tbody>

        @foreach (var item in Model)
        {
        <tr>
            <td class="details-control" data-Id="@item.Id"></td>
            <td>
                @Html.DisplayFor(modelItem => item.Name)
            </td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td> 
            </td>
        </tr>
        }
    </tbody>

</table>
